package butines.game.state;

import butines.core.Vector2f;
import butines.core.game.steering.behavior.ArrivalBehavior;
import butines.game.Unit;

public class MoveState extends AbstractState {
	
	private static final MoveState instance = new MoveState();
	
	public static MoveState getInstance() {
		return instance;
	}

	@Override
	public void enter(Unit owner) {
		owner.setEnemy(null);
		owner.getAnimManager().play("walk", true);
		owner.getSteering().getArrival().turnOn(owner.getTargetPoint());
//		owner.getSteering().getObstacleAvoidance().turnOn();
	}

	@Override
	public void leave(Unit owner) {
		owner.getAnimManager().stop();
		owner.getSteering().getArrival().turnOff();
//		owner.getSteering().getObstacleAvoidance().turnOff();
	}
	
	@Override
	public void execute(Unit owner) {
		ArrivalBehavior arrival = owner.getSteering().getArrival();
		Vector2f targetPoint = owner.getTargetPoint();
		
		arrival.getTarget().set(targetPoint);
		
		if (owner.isAtPoint(targetPoint, 4)) {
			owner.stay();
		}
	}
		
}
